package com.hxkj.service.impl;

import com.github.pagehelper.PageInfo;
import com.hxkj.client.service.UserFeedbackServiceClient;
import com.hxkj.domain.po.LastestMessage;
import com.hxkj.domain.po.UserFeedback;
import com.hxkj.service.UserFeedbackService;
import com.platform.common.domain.exception.CustomMessageException;
import com.platform.common.domain.result.ParameterDataStruct;
import com.platform.common.domain.result.ResultMessageStruct;
import com.platform.common.domain.to.PageTo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class UserFeedbackServiceImpl implements UserFeedbackService{
    @Autowired
    private UserFeedbackServiceClient userFeedbackServiceClient;

    @Override
    public PageInfo<UserFeedback> getList(UserFeedback userFeedback, PageTo pageParam) throws Exception {
        if (pageParam.getPageNum() == null || pageParam.getPageSize() == null) {
            pageParam.setPageNum(1);
            pageParam.setPageSize(10);
        }
        ParameterDataStruct<UserFeedback> parameterDataStruct = new ParameterDataStruct<>();
        parameterDataStruct.setData(userFeedback);
        parameterDataStruct.setPageTo(pageParam);
        return userFeedbackServiceClient.getList(parameterDataStruct);
    }

    @Override
    public void save(UserFeedback userFeedback) throws Exception {
        if(userFeedback == null || userFeedback.getUserId() == null) {
            throw new CustomMessageException(400, "用户的id不能为空!");
        }
        ResultMessageStruct  resultMessageStruct = userFeedbackServiceClient.save(userFeedback);
        if(resultMessageStruct.getCode() != 200) {
            throw new CustomMessageException("保存失败");
        }
    }
}
